﻿using System;
using System.Text;

namespace CSCodeLib.Helpers
{
    static class ArrayHelper
    {
        public static string[] SubArray(this string[] a, int index)
        {
            return SubArray(a, index, a.Length - index);
        }

        public static string[] SubArray(this string[] a, int index, int length)
        {
            string[] ret = new string[length];
            for (int i = 0; i < length && (i + index) < a.Length; i++)
            {
                ret[i] = a[i + index];
            }
            return ret;
        }

        public static bool Contains(this string[] a, string s)
        {
            foreach (string str in a)
            {
                if (s.Equals(str, StringComparison.InvariantCultureIgnoreCase))
                    return true;
            }
            return false;
        }

        public static string Join(this string[] a, string seperator)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string str in a)
            {
                sb.Append(seperator);
                sb.Append(str);
            }
            if (sb.Length > 0)
            {
                sb.Remove(0, seperator.Length);
            }
            return sb.ToString();
        }
    }
}
